import java.util.ArrayList;

/**
 * @author lzm
 * @date 2025/2/27 19:54
 * @description
 */
public class ThreadDemo {
    public static void main(String[] args) throws InterruptedException {
        // 创建线程要执行的任务
        Runnable task = () -> {
            System.out.println(Thread.currentThread().getName() + "：打印了hello world");
        };

        // 创建线程
        ArrayList<Thread> threads = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            Thread thread = new Thread(task, "thread-" + i);
            threads.add(thread);
        }

        // 启动所有线程
        for (Thread thread : threads) {
            thread.start();
            // 等待该线程执行完
            thread.join();
        }
    }

}